// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors, sized_box_for_whitespace, avoid_unnecessary_containers, avoid_print

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:mybaseplus/base/abstract/IFFR.dart';
import 'package:mybaseplus/base/abstract/IFFRefresh.dart';
import 'package:mybaseplus/base/abstract/IFFScaffold.dart';
import 'package:mybaseplus/base/tool/globalMethod/FFScreenValue.dart';
import 'package:mybaseplus/base/tool/language/baseLanguage/FFLgConst.dart';
import 'package:mybaseplus/base/widget/layout/FFLineContainer.dart';
import 'package:mybaseplus/base/widget/layout/FFTextButton.dart';
import 'package:mybaseplus/base/widget/page/FFScaffold.dart';
import 'package:mybaseplus/base/tool/extension/FFListExt.dart';

///文本弹窗
class TextToastWindow extends FFScaffold {
  String? text;
  Color? textColor;
  Color? bgColor;

  TextToastWindow({
    Key? key,
    this.text,
    this.textColor,
    this.bgColor,
  }) : super(key: key);

  @override
  TextToastWindowState createState() => TextToastWindowState();
}

class TextToastWindowState extends FFScaffoldState with MFFScaffold {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  TextToastWindow get widget => super.widget as TextToastWindow;

  @override
  IFFRefresh? get iffRefresh => refresh;
  late TextToastWindowRefresh refresh = TextToastWindowRefresh(state: this);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
    ffStyle?.ffBodyColor = Colors.transparent;
    ffStyle?.ffStatusBackgroundColor = Colors.transparent;
  }

  @override
  ffOnScaffoldTap() {
    // SmartDialog.dismiss();
  }

  @override
  Widget? ffBody(BuildContext context) {
    return Container(
      alignment: Alignment.bottomCenter,
      child: FFLineContainer(
        onClick: () {},
        direction: Axis.vertical,
        unconstrainedBox: true,
        width: globalScreenWidth(context) * 0.85,
        padding: EdgeInsets.symmetric(horizontal: 16.w,vertical: 16.w),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16.w),
          color: widget.bgColor ?? Colors.white,
        ),
        children: [
          FFTextButton(
            text: widget.text ?? FFLgConst.error(context),
            fontSize: 20.sp,
            fontColor: widget.textColor ?? Colors.black,
            fontLineHeight: 1.24,
            maxLines: 999,
            alignment: Alignment.center,
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }
}

class TextToastWindowRefresh with MFFRefresh {
  TextToastWindowState state;

  TextToastWindowRefresh({required this.state});

  @override
  ScrollPhysics? get ffRefreshPhysics => NeverScrollableScrollPhysics();

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  //具体请求业务
  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    List? list;
    await Future.wait([
      //HomeApi.index_recentlyPlayed(),
    ]).then((value) {
      list = value;
    });

    IFFR? r = list?.safeValue(0);
    return r ?? R(rStatus: RStatus.result);
  }
}
